package com.travel.travelServer.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.travel.travelServer.entity.Business;
import com.travel.travelServer.service.BusinessService;
import com.travel.travelServer.utils.BaseController;
import com.travel.travelServer.utils.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;

/**
 * (Business)表控制层
 *
 * @author makejava
 * @since 2024-03-01 15:38:45
 */
@RestController
@RequestMapping("/category")
public class BusinessController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private BusinessService BusinessService;

    /**
     * 分页查询所有数据
     *
     * @return 所有数据
     */
    @GetMapping
    public ResponseData selectAll(
        @RequestParam Map<String, Object> conditions
        ) {
        Page<Business> page = new Page<>(Integer.valueOf(conditions.get("page").toString()),Integer.valueOf(conditions.get("size").toString()));
        return ResponseData.success(this.BusinessService.page(page, conditions));
    }

    @GetMapping("/getMyBusiness")
    public ResponseData getMyBusiness(
            @RequestParam Map<String, Object> conditions
    ) {
        Page<Business> page = new Page<>(Integer.valueOf(conditions.get("page").toString()),Integer.valueOf(conditions.get("size").toString()));
        return ResponseData.success(this.BusinessService.getMyBusiness(page, conditions));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public ResponseData selectOne(@PathVariable Long id) {
        return ResponseData.success(this.BusinessService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param Business 实体对象
     * @return 新增结果
     */
    @PostMapping
    public ResponseData insert(@RequestBody Business Business) {
        return ResponseData.success(this.BusinessService.add(Business));
    }

    /**
     * 修改数据
     *
     * @param Business 实体对象
     * @return 修改结果
     */
    @PutMapping
    public ResponseData update(@RequestBody Business Business) {
        return ResponseData.success(this.BusinessService.update(Business));
    }

     /**
     * 单条删除数据
     *
     * @return 删除结果
     */
    @DeleteMapping("/{id}")
    public ResponseData delete(@PathVariable Long id) {
        return ResponseData.success(this.BusinessService.removeOne(id));
    }

    /**
     * 批量删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/batchDelete")
    public ResponseData delete(@RequestParam("idList") Long[] idList) {
        return ResponseData.success(this.BusinessService.batchRemove(Arrays.asList(idList)));
    }
}

